/**
 * Copyright (c) 2023 murenchao
 * taomu is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *       http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package cool.taomu.box.datasource

import com.google.inject.Provider
import com.google.inject.name.Named
import com.zaxxer.hikari.HikariDataSource
import javax.inject.Inject
import javax.sql.DataSource

class HikariDataSourceProvider implements Provider<DataSource> {
	HikariDataSource dataSource = new HikariDataSource();

	@Inject
	def void setDirver(@Named("hikari.jdbc.driver") String driverCLass) {
		dataSource.driverClassName = driverCLass;
	}

	@Inject
	def void setJdbcUrl(@Named("hikari.jdbc.url") String url) {
		dataSource.jdbcUrl = url;
	}

	@Inject
	def void setUname(@Named("hikari.jdbc.username") String uname) {
		dataSource.setUsername = uname;
	}

	@Inject
	def void setPasswd(@Named("hikari.jdbc.password") String pwd) {
		dataSource.setPassword = pwd;
	}
	
	@Inject
	def void connectionTimeout(@Named("hikari.connectionTimeout") long value) {
		dataSource.connectionTimeout = value;
	}
	@Inject
	def void validationTimeout(@Named("hikari.validationTimeout") long value) {
		dataSource.validationTimeout = value;
	}
	@Inject
	def void idleTimeout(@Named("hikari.idleTimeout") long value) {
		dataSource.idleTimeout = value;
	}
	@Inject
	def void leakDetectionThreshold(@Named("hikari.leakDetectionThreshold") long value) {
		dataSource.leakDetectionThreshold = value;
	}
	@Inject
	def void maxLifetime(@Named("hikari.maxLifetime") long value) {
		dataSource.maxLifetime = value;
	}
	@Inject
	def void maxPoolSize(@Named("hikari.maxPoolSize") int value) {
		dataSource.maximumPoolSize =  value;
	}
	@Inject
	def void minIdle(@Named("hikari.minIdle") int value) {
		dataSource.minimumIdle = value;
	}
	@Inject
	def void initializationFailTimeout(@Named("hikari.initializationFailTimeout") long value) {
		dataSource.initializationFailTimeout = value;
	}
	@Inject
	def void connectionInitSql(@Named("hikari.connectionInitSql") String value) {
		dataSource.connectionInitSql = value;
	}
	@Inject
	def void connectionTestQuery(@Named("hikari.connectionTestQuery") String value) {
		dataSource.connectionTestQuery = value;
	}
	@Inject
	def void dataSourceClassName(@Named("hikari.dataSourceClassName") String value) {
		dataSource.dataSourceClassName = value;
	}
	@Inject
	def void dataSourceJndiName(@Named("hikari.dataSourceJndiName") String value) {
		dataSource.dataSourceJNDI = value;
	}
	@Inject
	def void exceptionOverrideClassName(@Named("hikari.exceptionOverrideClassName") String value) {
		dataSource.exceptionOverrideClassName = value;
	}
	@Inject
	def void poolName(@Named("hikari.poolName") String value) {
		dataSource.poolName = value;
	}
	@Inject
	def void schema(@Named("hikari.schema") String value) {
		dataSource.schema = value;
	}
	@Inject
	def void transactionIsolationName(@Named("hikari.transactionIsolationName") String value) {
		dataSource.transactionIsolation = value;
	}
	@Inject
	def void isAutoCommit(@Named("hikari.autoCommit") boolean value) {
		dataSource.autoCommit = value;
	}
	@Inject
	def void isReadOnly(@Named("hikari.readOnly") boolean value) {
		dataSource.readOnly = value;
	}
	@Inject
	def void isIsolateInternalQueries(@Named("hikari.isolateInternalQueries") boolean value) {
		dataSource.isolateInternalQueries = value;
	}
	@Inject
	def void registerMbeans(@Named("hikari.registerMbeans") boolean value) {
		dataSource.registerMbeans = value;
	}
	@Inject
	def void isAllowPoolSuspension(@Named("hikari.allowPoolSuspension") boolean value) {
		dataSource.allowPoolSuspension = value;
	}
	@Inject
	def void keepaliveTime(@Named("hikari.keepaliveTime") long value) {
		dataSource.keepaliveTime = value;
	}
	
	def void configure(HikariDataSource dataSource) {
	}

	override get() {
		this.configure(this.dataSource);
		return dataSource;
	}
}
